<script type="text/javascript">
$(document).ready(function() {

   	     // Lega l'evento updateFeedTree per l'aggiornamento dell'albero
  	     $('#feedTreeContent').bind("updateFeedTree", function(event) {
        	 $('#feedTreeContent').empty();
        	 
        	 $('#feedTreeContent').fileTree({ 
                 expandSpeed: 50,
                 collapseSpeed: 50,
                 multiFolder: false
              }, function(data) {
            	  loadNews(data,'/news/loadnewslist',function(data) {
                      $('#newsList').html(data);
                      $('.scroll').css('height','500px');
                      $("#headergreybox").text("<?= $this->translate('news')?>");
                 });
              });
         });
         
         // Associa l'azione al click sul bottone di aggiunta feed
         $('#addFeedTree').click(function() {
     	     loadView('/feed/activeadduserfeed', $('#newsList'), function(data) {
      	    	prepareInputsForHints();
         	 });
      	    $('.scroll').css('height','auto'); 
      	    $("#headergreybox").text("<?= $this->translate('addNewFeed')?>");
         });

         // Associa le azioni al click sul bottone di cancellazione per feed e categorie
         $('#removeFeedTree').click(function() {
     	     var elem = $('.selectedFT');
     	     var boxMessages = null;
     	     var url = '';
     	     
      	     // Rimozione feed
             if (elem.parent().hasClass('file')) {
                 url = '/feed/deleteuserfeed';
                 boxMessages = {
         	         msg : "<?= $this->translate('msgDelFeed')?>",
         	         boxTitle : "<?= $this->translate('titleDelFeed')?>",
         	         msgStatus: "<?= $this->translate('statusDel')?>"
             	 };
         	    
             } else if (elem.parent().hasClass('directory')) {
           	     // Rimozione categoria
            	 url = '/category/deleteusercategory'; 
            	 boxMessages = {         
                     msg : "<?= $this->translate('msgDelCategory')?>",
                     boxTitle : "<?= $this->translate('titleDelCategory')?>",
                     msgStatus: "<?= $this->translate('statusDel')?>"
                 };
             } else {
                 // Non è stato selezionato alcun elemento da rimuovere!
            	 jQuery.facebox("<?= $this->translate('noselection')?>");
                 return false;
             }
             // Chiamata alla funzione di rimozione con in parametri preimpostati
             deleteUserElement(elem.attr('rel'), url, elem.parent(), boxMessages);
         });

         // Associa l'azione del click al bottone di ricerca news
         $('#buttonNewsSearch').click(function() {
             $('#newsList').html('<img alt="<?=$this->translate('loadMsg') ?>" src="/img/ajax-loader.gif"/><?=$this->translate('loadMsg') ?>');
             var keywords = $('#inputNewsSearch').val();
             loadNews(keywords,'/news/searchusernews',function(data) {
                 $('#newsList').html(data);
                 $('.scroll').css('height','500px');
             });
         });

         // Associa l'azione al click sul bottone di visualizzazione news importanti
         $('#importantNewsLink').click(function(event) {
       	     event.preventDefault();
             // Remove all previus selected CSS class
             $('.selectedFT').removeClass('selectedFT');
             
             // Add selected CSS class
             $(this).addClass('selectedFT');
             
          	 loadView('/news/loadimportantnewslist', null, function(data) {
                  $('#newsList').html(data);
             });
         });
         
         // Force Feed Tree to update itself
         $('#feedTreeContent').trigger("updateFeedTree");

         // Init top ten box
         loadView('/index/loadtopten', null, function(data) {
             var dataC = jQuery(data).children('#intro');

             $('#userTopTen').html(dataC.html());

             jQuery('#listTopTen').accordion({
                 autoHeight: false,
                 collapsible: true
             }).accordion('activate',false);

             //Abilita il click per l'aggiunta dei feed dalla top ten 
             $(".addboxtreetop").click(function(event){
                 var feedID = $(this).attr('id').split('-')[1];
                 var feedURL = $('#feedid-'+feedID).attr('href');
                 event.preventDefault();
                 var options = {feedURL:feedURL};
                 loadViewAddUserFeed("/feed/activeadduserfeedtopsuggest", options, function(data){
                    $('#newsList').html(data);
                    $('.scroll').css('height','auto');
                    $("#headergreybox").text("<?= $this->translate('addMyFeed')?>");
                    prepareInputsForHints();
                 });
             });

             $('.tip').tooltip({
                 track: true,
                 delay: 0,
                 showURL: false,
                 showBody: " - ",
                 fade: 250
             });

         });

         // Init polling for upgrade user's feeds
         $('#feedTreeContent').poll({
             url: "/news/upgradeusernews",
             interval: 3600000,
             success: function(data) { return false; }
         });

});
</script>

<!--###Blocco Centrale###-->
    <div id="content">
        <div id="columns">    
        <ul id="column1Home" class="column">
            <li class="widget color-myOrange" id="intro">
                <div class="widget-head">
                    <h3><?= $this->translate('manageFeeds')?></h3> 
                </div>
                <div class="widget-contentHome">
                    <div class="feedmenubox">
	                    <ul class="feedmenuul">    
	                        <li class="feedmenuitem">
	                            <img id="addFeedTree" 
	                                 class="feedmenuimage feedmenuImageLargeSeparator tip" 
	                                 src="/img/feedtree/images/add.png"
	                                 title="<?= $this->translate('addNewFeed')?>" /> 
	                        </li>
	                        <li class="feedmenuitem">
	                            <img id="removeFeedTree"
	                                 class="feedmenuimage feedmenuImageSeparator tip" 
	                                 src="/img/feedtree/images/remove.png"
	                                 title="<?= $this->translate('removeFeed')?>" />
	                        </li>
	                    </ul>
                    </div>
                    
                    <div id="feedTreeContent" class="FTContent">
                        <!-- Feed Tree -->                            
                    </div>
                    
                    <div class="boxButtonFT">
	                    <div id="buttonisImportant" class="BIImportant">
	                        <ul class="ulBoxButtonFT">
	                            <li class="ItemButtonFT">
	                               <img class="imgFT" src="/img/boxbar/isImportant.png" alt="is important" />
	                            </li>
	                            <li class="ItemButtonFT">
	                               <a id="importantNewsLink" href="#" class="aBF"><?= $this->translate('importantnews')?></a>
	                            </li>
	                        </ul>
	                    </div>
                    </div>
                </div>
            </li>
            <!-- <li id="userTopTen" class="borderWidget"> -->
            <li id="userTopTen" class="widget color-myGrey">
               <!-- Lista TopTen in user -->
            </li>
        </ul>
        <ul id="column2Home" class="column">
            <li class="widget color-myGrey">  
                <div class="widget-head">
                    <h3 id="headergreybox"><?= $this->translate('news')?></h3>
                </div>
                <div class="widget-contentHome">
                    <div class="scroll">
	                    <div id="newsList" class="newsList">
	                    <!-- Lista delle news -->
	                    </div>
                    </div>
                </div>
            </li>
        </ul>
        <div style="clear: both;"></div>
        </div>
    </div><!--contentCenter-->